rm(list=ls(all=TRUE))

library(foreign)

# Change this to  your working directory
mywd <- "/Users/paulmusgrave/Dropbox/0001 Academic Projects/Ongoing/0127 Oil Islam Women/ISQ Accepted Submission/Replication"

setwd(paste(mywd,"/Data",sep=""))

ISQ_Fig1<-read.dta("ISQ_Fig1_Replication.dta")

require(lattice)

ISQ_Fig1<-data.frame(ISQ_Fig1)

# Proportion that agree that men have more right to scarce jobs
work_discrim<- dotplot(reorder(countryname, oil_rents_pc) ~ workplace_pct, data=ISQ_Fig1, groups=Gender,
        main="Men have more right \n to scarce jobs",
        xlab="Percent who agree",
        par.settings = simpleTheme(col=c("black", "black"),
                                   pch=c(1,3), cex=1.25),
        auto.key = list(points=TRUE,text=c("Men","Women"), space="top", columns=2))

# Proportion that agree that men make better political leaders than women
patriarchy<- dotplot(reorder(countryname, oil_rents_pc) ~ patriarchy_pct, data=ISQ_Fig1, groups=Gender,
        main="Men make better political \n leaders than women",
        xlab="Percent who agree",
        par.settings = simpleTheme(col=c("black", "black"),
                                   pch=c(1,3), cex=1.25),
        auto.key = list(points=TRUE,text=c("Men","Women"), space="top", columns=2))

# Excess Fertility
require(latticeExtra)

excess_fertility<- dotplot(reorder(countryname, oil_rents_pc) ~ fam_gap_mar, data=ISQ_Fig1, groups=Gender,
                           main="Excess Fertility over \n Desired Number of Children",
                           xlab="Excess Fertility (Married Parents Only)",
                           par.settings = simpleTheme(col=c("black", "black"),
                                                      pch=c(1,3), cex=1.25),
                           auto.key = list(points=TRUE,text=c("Men","Women"), space="top", columns=2))

excess_fertility <- excess_fertility + layer(panel.abline(v=0, lty=2, col=2))
print(excess_fertility)

# Proportion agreeing that it is important for a woman to be educated
women_edu<- dotplot(reorder(countryname, oil_rents_pc) ~ women_edu_pct, data=ISQ_Fig1, groups=Gender, 
        main="It is important for \n women to be educated",
        xlab="Percent who agree",
        par.settings = simpleTheme(col=c("black", "black"),
                                   pch=c(1,3), cex=1.25),
        auto.key = list(points=TRUE,text=c("Men","Women"), space="top", columns=2))

######################################################################################
setwd("../Drafts/Charts")

tiff("ISQFINALMainBodyFigure1.tiff",
		height=10,
		width=10,
		units="in",
		res=300)
# Combining plots
print(work_discrim, split = c(1, 1, 2, 2), more = TRUE)
print(patriarchy, split = c(2, 1, 2, 2), more = TRUE)
print(excess_fertility, split = c(1, 2, 2, 2), more = TRUE)
print(women_edu, split = c(2, 2, 2, 2), more = FALSE)  # more = FALSE is redundant
dev.off()
